package cn.tedu.onlinestore.address.controller;

import cn.tedu.onlinestore.address.pojo.dto.AddressParam;
import cn.tedu.onlinestore.address.pojo.vo.AddressVO;
import cn.tedu.onlinestore.address.service.AddressService;
import cn.tedu.onlinestore.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    AddressService addressService;

    @GetMapping("address/{id}")
    public JsonResult address(@PathVariable Integer id) {
        log.debug("查询收获地址：{}", id);
        List<AddressVO> addressVO = addressService.address(id);
        return JsonResult.ok(addressVO);
    }

    @PostMapping("saveAddress")
    public JsonResult saveAddress(AddressParam addressParam){
        log.debug("新增收获地址：{}", addressParam);
        addressService.saveAddress(addressParam);
        return JsonResult.ok();
    }
    @GetMapping("addressById/{id}")
    public JsonResult addressById(@PathVariable Long id){
        log.debug("回显收获地址：{}", id);
        AddressVO addressVO = addressService.addressById(id);
        return JsonResult.ok(addressVO);
    }

    @PostMapping("deleteAddress/{addressId}")
    public JsonResult deleteAddress(@PathVariable Long addressId){
        log.debug("删除收获地址：{}", addressId);
        addressService.deleteAddress(addressId);
        return JsonResult.ok();
    }

}
